import request from '../utils/request';

/**
 * 登录
 * @param data
 */
export const userLogin =(data:Object)=>{
    return request({
        url: '/user/login',
        method: 'post',
        data: data
    })
}

/**
 * 注册
 * @param data
 */
export const register = (data:Object) => {
    return request({
        url: '/user/register',
        method: 'post',
        data: data
    })
}

/**
 * 查询用户的菜单权限
 */
export const getUserMenu = () => {
    return request({
        url: '/user/getMenuList',
        method: 'get'
    })
}

/**
 * 分页查询
 */
export const queryUserPage = (pageNo:number,pageSize:number,username:String,tableInfo:Object) => {
    return request({
        url: `/user/queryUserPage?pageNo=${pageNo}&pageSize=${pageSize}&username=${username}`,
        method: 'get'
    }).then(res =>{
        tableInfo.total = res.data.total
        tableInfo.records = res.data.records
    })
}

/**
 * 删除用户
 */
export const removeUser = (id: number) => {
    return request({
        url: `/user/remove?id=${id}`,
        method: 'post'
    })
}

/**
 * 保存用户
 */
export const saveUser = (data:Object) => {
    return request({
        url: '/user/saveUser',
        method: 'post',
        data: data
    })
}

/**
 * 获取当前用户信息
 */
export const getCurrentUser = () => {
    return request({
        url:'/user/getCurrentUser',
        method: 'get'
    })
}

/**
 * 修改头像
 * @param data
 */
export const changeAvatar = (data:Object)=>{
    return request({
        url: `/user/changeAvatar?avatar=${data}`,
        method: 'post'
    })
}

/**
 * 修改密码
 * @param oldPassword
 * @param newPassword
 */
export const changePassword = (oldPassword:string,newPassword:string) => {
    return request({
        url: `/user/changePassword?oldPassword=${oldPassword}&newPassword=${newPassword}`,
        method: 'post'
    })
}
